package com.api.rest.controller;

import com.api.rest.exception.resolver.AuthFailException;
import com.mms.pojo.User;
import com.mms.service.UserService;
import com.mms.utils.RequestUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by dan3652@sina.com on 2016-12-02 11:29.
 */
@RestController
public class TestController {
    Logger logger = Logger.getLogger(TestController.class);
    @Autowired
    private UserService userService;

    @RequestMapping(value = "wxInterface")
    public Object interfaces(HttpServletResponse response, HttpServletRequest request){
        String method = RequestUtils.getQueryParam(request,"method");
        System.out.println("=============================================="+method);
        if(StringUtils.isEmpty(method)){
            new AuthFailException("必须传method参数！");
        }
        if("test".equals(method)){
            return test(response,request);
        }
        return null;
    }

    public Object test(HttpServletResponse response,HttpServletRequest request){
        List<Object> list = new ArrayList();
        Map<String,Object> obj = new HashMap<String,Object>();
        obj.put("status","success");
        list.add(obj);
        return list;
    }

    @RequestMapping(value = "hibnateTest")
    public Object hibernateTest(HttpServletResponse response,HttpServletRequest request){
        /*User user = new User();
        user.setAge(22);
        user.setPassword("123456");
        user.setUserName("sb");*/
//        List<User> list = userService.findByIn(new Integer[]{1, 2, 3});
        List<User> list = userService.getAll();
        logger.info(list);
        return list;
    }
}
